package com.cooper.controllers.admin;

import javax.servlet.http.HttpServletRequest;

import net.paoding.rose.web.ControllerInterceptorAdapter;
import net.paoding.rose.web.Invocation;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cooper.domain.UserSession;
import com.cooper.util.Controllers;

/**
 * 
 * @Description: <br>
 * @Date: Jan 10, 2014 9:02:51 PM<br>
 * @Copyright (c) 2014 MiXuan <br> * 
 * @since 1.0
 * @author coral
 */
public class AdminInterceptor extends ControllerInterceptorAdapter {
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Override
	protected Object before(Invocation inv) throws Exception {
		logger.debug("invoking " + inv.getControllerClass().getName() + "." + inv.getMethod().getName());
		HttpServletRequest request = inv.getRequest();
		UserSession userSession = Controllers.getUserSession(inv);
		if(null == userSession || null == userSession.getUserInfo()){
			String originURL = request.getRequestURL().toString();
            return "/login?originURL=" + originURL;
		}
		return super.before(inv);
	}

	@Override
	protected Object after(Invocation inv, Object instruction) throws Exception {
		// TODO Auto-generated method stub
		return super.after(inv, instruction);
	}

}
